<?php
/**
* YouPinKu.php file
* create by ljanson
* @2013-3-6
*/
require_once 'function.php';
$data = isset($_POST["data"]) ? $_POST["data"] : "";

if($data){
	header("Content-Type: text/html; charset=utf-8");
	require_once 'DBFactory.php';
	$db = DBFactory::getInstance("YouPinKu");
	$ConverData = json_decode($data, true);
	$sql = "";
	
	foreach($ConverData as $key => $val){
		$sql .= "INSERT INTO `ProductInformation`(`Identifier`,`Name`,`BrandIdentifier`,`Picture`,`PublishedDate`,`ListPrice`,`Price`,`Discount`,`PurchasedCount`,`Favorite`,`Collected`,`Editor`,`EditorialReviews`,`RealUrl`,`IsFreeDistribution`,`Ratio`,`Priority`,`BrandPriority`,`Status`) VALUES({$val["id"]}, '{$val["title"]}', '{$val["brand_id"]}', '{$val["picture_url"]}', '{$val["published_date"]}', {$val["list_price"]}, {$val["price"]}, {$val["discount"]}, {$val["purchaser_count"]}, {$val["shared_count"]}, {$val["collected_count"]}, '{$val["editor"]}', '{$val["description"]}', '{$val["url"]}', {$val["is_free_distribution"]}, {$val["commission_percentage"]}, {$val["priority"]}, {$val["brand_priority"]}, {$val["status"]}) ON DUPLICATE KEY UPDATE `Name`='{$val["title"]}',`BrandIdentifier`='{$val["brand_id"]}',`Picture`='{$val["picture_url"]}',`PublishedDate`='{$val["published_date"]}',`ListPrice`={$val["list_price"]},`Price`={$val["price"]},`Discount`={$val["discount"]},`PurchasedCount`={$val["purchaser_count"]},`Favorite`={$val["shared_count"]},`Collected`={$val["collected_count"]},`Editor`='{$val["editor"]}',`EditorialReviews`='{$val["description"]}',`RealUrl`='{$val["url"]}',`IsFreeDistribution`={$val["is_free_distribution"]},`Ratio`={$val["commission_percentage"]},`Priority`={$val["priority"]},`BrandPriority`={$val["brand_priority"]},`Status`={$val["status"]};";
	}
	
	$res = $db->execute($sql);
	$ret = $res ? 1 : 2;
	$msg = $res ? "执行成功" : "执行失败";
	echo json_encode(array("ret"=>$ret, "msg"=>$msg));
	exit;
}
else{
	echo json_encode(array("ret"=>0, "msg"=>"参数错误，数据为空"));
	exit;
}
